<!DOCTYPE html>
<html lang="zh-CN">
<head>
 

<#include "bases/global_style.ftl">
<#include "bases/global_js.ftl">
 
 	<script>

		jQuery(document).ready(function() 
		{   
 		 
			App.init();
            UINestable.init();
 			 
		});
 
        var parentIndex = 0;
        var editId = 0;
		function addSubMenu(parent_text, index, level) {
			
        	
    		jConfirm('将在"'+parent_text+'"菜单下增加子菜单', '提示', function(r) {
  			  if(r==true){
                showPopup(parent_text, level);
                parentIndex = index;
              }
    		});
		}

        function doEditMenu() {
            var editMenuText=document.getElementById("editMenuText").value;
            var editUrl=document.getElementById("editUrl").value;
            var count = true;

            resetLabel();
            if (editMenuText == null || editMenuText == "") {
                document.getElementById("editMenuText").style.borderColor = "#FF0000";
                count=false;
            }

            if (count) {
                $("#postaction3").val("edit");
                $("#editId").val(editId);
                $("#editForm").submit();
            }
        }

        function doAddMenu() {
            var addMenuText=document.getElementById("addMenuText").value;
            var addParentText=document.getElementById("addParentText").value;
            var addUrl=document.getElementById("addUrl").value;
            var addLevel=document.getElementById("addLevel").value;
            var addIcon=document.getElementById("addIcon").value;
            var addMinRoleLevel=document.getElementById("addMinRoleLevel").value;
            var count = true;

            resetLabel();
            if (addMenuText == null || addMenuText == "") {
                document.getElementById("addMenuText").style.borderColor = "#FF0000";
                count=false;
            }
 
            if (addIcon == null || addIcon == "") {
                document.getElementById("addIcon").style.borderColor = "#FF0000";
                count=false;
            }
            if (addMinRoleLevel == null || addMinRoleLevel == "") {
                document.getElementById("addMinRoleLevel").style.borderColor = "#FF0000";
                count=false;
            }

            if (count) {
                $("#postaction2").val("insert");
                $("#addParentIndex").val(parentIndex);
                $("#addForm").submit();
            }

        }

        function updateMenu() {
            $("#loading").showLoading(); 
            $('#postaction1').val('update');
            $('#trueLeftMenu').val($('#nestable_list_1_output').val());
            $('#searchform').ajaxSubmit({
                success:function(data){
                  	 $('#loading').hideLoading();
                 }
             });
      

        }

        function resetLabel() {
            $("#insertdlg input").each(function(index, element)
            {
                $(this).css('borderColor','#BBB');
            });
            $("#editdlg input").each(function(index, element)
            {
                $(this).css('borderColor','#BBB');
            });
        }

        function showEditDiv(url, text) {//弹出层
            var backDiv =$("#backDiv");
            backDiv.css('top','0%');
            backDiv.css('left','0%');
            backDiv.css('width','100%');
            backDiv.css('height','100%');
            backDiv.css('visibility','visible');

            var realDiv =$("#editDiv");
            realDiv.css('top','30%');
            realDiv.css('left','30%');
            realDiv.css('width','40%');
            realDiv.css('height','auto');
            realDiv.css('visibility','visible');

            document.getElementById("editMenuText").value = text;
            document.getElementById("editUrl").value = url;
        }

        function showPopup(parent_text, level) {//弹出层
            var backDiv =$("#backDiv");
            backDiv.css('top','0%');
            backDiv.css('left','0%');
            backDiv.css('width','100%');
            backDiv.css('height','100%');
            backDiv.css('visibility','visible');

            var realDiv =$("#realDiv");
            realDiv.css('top','30%');
            realDiv.css('left','30%');
            realDiv.css('width','40%');
            realDiv.css('height','auto');
            realDiv.css('visibility','visible');

            document.getElementById("addParentText").value = parent_text;
            document.getElementById("addLevel").value = parseInt(level)+1;
        }

        function hidePopup() {//关闭层
            $("#insertdlg input").each(function(index, element)
            {
                $(this).val(null);
                $(this).css('borderColor','#BBB');
            });
            $("#editdlg input").each(function(index, element)
            {
                $(this).val(null);
                $(this).css('borderColor','#BBB');
            });

            resetLabel();
            var backDiv = document.getElementById("backDiv");
            backDiv.style.visibility = "hidden";

            var realDiv = document.getElementById("realDiv");
            realDiv.style.visibility = "hidden";

            var editDiv = document.getElementById("editDiv");
            editDiv.style.visibility = "hidden";
        }

        function allDivHide() {
            hidePopup();
        }

        function deleteMenu(id, text) {
        	
    		jConfirm('确定删除"' + text + '?', '提示', function(r) {
  			  if(r==true){
         
                $('#postaction1').val('delete');
                $('#postarg').val(id);
                $("#searchform").submit();
  			  }
    		});
        }

        function editMenu(id, url, text) {
            showEditDiv(url, text);
            editId = id;
            $("#oldUrl").val(url);
        }
 
	</script>
</head>
<!-- END HEAD -->
<!-- BEGIN BODY -->
<body>
	<!-- END HEADER -->

    <div id="backDiv" onclick="allDivHide()" style="position: absolute;visibility: hidden;position:fixed;overflow: hidden;solid: #000000;background-color: #000000;padding: 1px;z-index: 99;filter:alpha(opacity=50);opacity: 0.5;"></div>

    <div id="editDiv" class="row-fluid" style="position: absolute;visibility: hidden;overflow: hidden;padding: 1px;z-index: 100;background-color: #FFFFFF;">
        <div class="span12">
            <div class="portlet box green" style="padding: 0px;margin:0px;">
                <div class="portlet-title">
                    <div class="caption"><i class="fa fa-edit"></i>编辑菜单</div>
                    <a href="javascript:allDivHide();" class="remove"></a>
                </div>

                <div class="portlet-body flip-scroll">
                    <form id="editForm" action="<@spring.url '/left_menu_manage'></@spring.url>" method="POST">
                        <table class="table-bordered table-striped table-condensed flip-content">
                            <input  type="hidden" id="postaction3" name="postaction" />
                            <input  type="hidden" id="editId" name="editId" />
                            <input  type="hidden" id="oldUrl" name="oldUrl" />
                            <tbody id="editdlg" role="alert" aria-live="polite" aria-relevant="all">
                            <tr class="even">
                                <td style="text-align: right;">菜单名称</td>
                                <td class="even">
                                    <input class="m-wrap span8" style="margin-top: 10px" type="text" id="editMenuText" name="editMenuText" value="" placeholder="请输入菜单项对应页面名称" />
                                </td>

                            </tr>
                            <tr class="even">
                                <td style="text-align: right;">url</td>
                                <td class="center">
                                    <input class="m-wrap span8" style="margin-top: 10px" id="editUrl" name="editUrl" value="" placeholder="请输入该菜单项对应的url"/>
                                </td>
                            </tr>
                            <#--<tr class="even">-->
                                <#--<td style="text-align: right;">icon</td>-->
                                <#--<td class="center">-->
                                    <#--<input class="m-wrap span8" style="margin-top: 10px" id="addIcon" name="icon" value="fa fa-user" placeholder="请输入该菜单项对应的icon"/>-->
                                <#--</td>-->
                            <#--</tr>-->
                            <#--<tr class="even">-->
                                <#--<td style="text-align: right;">最低权限等级要求</td>-->
                                <#--<td class="center">-->
                                    <#--<select id="addMinRoleLevel" name="minRoleLevel" class="span8 small m-wrap" value="5" style="margin-top: 10px" placeholder="">-->
                                    <#--<#if user_info.getRoleId() gt 4><option value="5">superadmin</option></#if>-->
                                    <#--<#if user_info.getRoleId() gt 3><option value="4">admin</option></#if>-->
                                    <#--<#if user_info.getRoleId() gt 2><option value="3">preadmin</option></#if>-->
                                    <#--<#if user_info.getRoleId() gt 1><option value="2">visitall</option></#if>-->
                                        <#--<option value="1">visitor</option>-->
                                    <#--</select>-->
                                <#--</td>-->
                            <#--</tr>-->
                            </tbody>
                        </table>
                        </br>
                        <div class="controls controls-row" style="text-align: right;">
                            <input type="button" value="提交" class="btn green" onclick="doEditMenu()"/>
                            <input type="button" value="取消" class="btn green" onclick="allDivHide()" />
                        </div>
                        <div id="Pagination" class="pagination">

                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <div id="realDiv" class="row-fluid" style="position: absolute;visibility: hidden;overflow: hidden;padding: 1px;z-index: 100;background-color: #FFFFFF;">
        <div class="span12">
            <div class="portlet box green" style="padding: 0px;margin:0px;">
                <div class="portlet-title">
                    <div class="caption"><i class="fa fa-edit"></i>添加子菜单</div>
                    <a href="javascript:allDivHide();" class="remove"></a>
                </div>

                <div class="portlet-body flip-scroll">
                    <form id="addForm" action="<@spring.url '/left_menu_manage'></@spring.url>" method="POST">
                        <table class="table-bordered table-striped table-condensed flip-content">
                            <input  type="hidden" id="postaction2" name="postaction" />
                            <input  type="hidden" id="addParentIndex" name="parentIndex" />
                            <tbody id="insertdlg" role="alert" aria-live="polite" aria-relevant="all">
                            <tr class="even">
                                <td style="text-align: right;">菜单名称</td>
                                <td class="even">
                                    <input class="m-wrap span8" style="margin-top: 10px" type="text" id="addMenuText" name="menuText" value="" placeholder="请输入菜单项对应页面名称" />
                                </td>

                            </tr>
                            <tr class="even">
                                <td style="text-align: right;">根菜单</td>
                                <td class="center">
                                    <input class="m-wrap span8" style="margin-top: 10px" readonly="readonly" id="addParentText" name="parentText" value="" />
                                </td>
                            </tr>
                            <tr class="even">
                                <td style="text-align: right;">url</td>
                                <td class="center">
                                    <input class="m-wrap span8" style="margin-top: 10px" id="addUrl" name="url" value="" placeholder="请输入该菜单项对应的url"/>
                                </td>
                            </tr>
                            <tr class="even">
                                <td style="text-align: right;">菜单level</td>
                                <td class="center">
                                    <input class="m-wrap span8" style="margin-top: 10px" readonly="readonly" id="addLevel" name="level" value="" />
                                </td>
                            </tr>

                            <tr class="even">
                                <td style="text-align: right;">icon</td>
                                <td class="center">
                                    <input class="m-wrap span8" style="margin-top: 10px" id="addIcon" name="icon" value="fa fa-user" placeholder="请输入该菜单项对应的icon"/>
                                </td>
                            </tr>

                            <tr class="even">
                                <td style="text-align: right;">最低权限等级要求</td>
                                <td class="center">
                                    <select id="addMinRoleLevel" name="minRoleLevel" class="span8 small m-wrap" value="5" style="margin-top: 10px" placeholder="">
                                        <#if user_info.getRoleId() gt 4><option value="5">superadmin</option></#if>
                                        <#if user_info.getRoleId() gt 3><option value="4">admin</option></#if>
                                        <#if user_info.getRoleId() gt 2><option value="3">preadmin</option></#if>
                                        <#if user_info.getRoleId() gt 1><option value="2">visitall</option></#if>
                                        <option value="1">visitor</option>
                                    </select>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                        </br>
                        <div class="controls controls-row" style="text-align: right;">
                            <input type="button" value="提交" class="btn green" onclick="doAddMenu()"/>
                            <input type="button" value="取消" class="btn green" onclick="allDivHide()" />
                        </div>
                        <div id="Pagination" class="pagination">

                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

<#include "bases/navhead.ftl">
<#include "bases/sidebar.ftl">

    <div class="page-container secMenu-content" id="loading">    
 
        <div class="page-content">
     
            <div class="container-fluid">

                <div class="row-fluid">
                    <div class="span12">
                        <div class="portlet box green">
                            <div class="portlet-title">
                                <div class="caption"><i class="fa fa-cogs"></i>菜单管理</div>
	                            <div class="tools">
	                                <a href="javascript:window.location.reload()" class="reload"></a>
	                            </div>
                            </div>
							<div class="portlet-body flip-scroll">

                                <menu id="nestable-menu">
                                    <button type="button" class="control-btn btn blue" data-action="expand-all" onclick="javascript:$('.dd').nestable('expandAll');">全部展开</button>
                                    <button type="button" class="control-btn btn blue" data-action="collapse-all" onclick="javascript:$('.dd').nestable('collapseAll');">全部收起</button>
                                </menu>
															
							<form id="searchform" action="<@spring.url '/left_menu_manage'></@spring.url>" method="POST">
                                <input  type="hidden" id="postaction1" name="postaction" />
                                <input  type="hidden" id="postarg" name="postarg" />

								<div class="controls controls-row">
									<#if left_menu_list?exists><button type="button" class="control-btn btn green" style="margin-left: 20px" onclick="addSubMenu('根目录', '0', '0')"><i class="fa fa-plus"></i> 添加菜单</button></#if>
                                    <#if left_menu_list?exists><button type="button" class="control-btn btn blue"  style="margin-left: 20px" onclick="updateMenu()">提交新的菜单</button></#if>
                                </div>

                                <div class="controls controls-row">
                                    <input type="hidden" id="nestable_list_1_output" class="m-wrap span12"></textarea>
                                    <input type="hidden" id="trueLeftMenu" name="newLeftMenu" class="m-wrap span12"/>
                                </div>
								<!-- 显示菜单树 begin -->
                               
                                <div class="portlet-body ">
                                    <div class="dd" id="nestable_list_1">
                                        <ol class="dd-list">
                                            <#list left_menu_list as sbl>
                                                <li class="dd-item dd3-item"data-id="${sbl.getId()}">
                                                    <div class="dd-handle dd3-handle"></div>
                                                    <div class="dd3-content" >
                                                        ${sbl.getText()}
                                                        <#if FtlOperationUtil.isNull(sbl.getUrl()) >
                                                            <a style="float:right;" class="btn mini blue" onclick="editMenu(${sbl.getId()}, '', '${sbl.getText()}')"><i class="fa fa-edit"></i>编辑</a>
                                                        <#else>
                                                            <a style="float:right;" class="btn mini blue" onclick="editMenu(${sbl.getId()}, '${sbl.getUrl()}', '${sbl.getText()}')"><i class="fa fa-edit"></i>编辑</a>
                                                        </#if>
                                                        <#if sbl.hasSubMenu()>
                                                            <a style="float:right;" class="btn mini black" onclick="deleteMenu(${sbl.getId()}, '${sbl.getText()}')"><i class="fa fa-trash"></i>删除</a>
                                                        <#else>
                                                            <a style="float:right;" class="btn mini black" onclick="alert('指定了Url或者有子菜单的菜单项不能被删除，请先去掉Url或者把所有子菜单项移开并提交！');"><i class="fa fa-trash"></i>删除</a>
                                                        </#if>
                                                        <#if FtlOperationUtil.isNull(sbl.getUrl()) >
                                                            <a style="float:right;" class="btn mini green" onclick="addSubMenu('${sbl.getText()}', '${sbl.getIndex()}', '${sbl.getLevel()}')"><i class="fa fa-plus"></i>添加子菜单</a>
                                                        <#else>
                                                            <a style="float:right;" class="btn mini green" onclick="alert('指定了Url的菜单项不能添加子菜单，请先通过编辑去掉Url');"><i class="fa fa-plus"></i>添加子菜单</a>
                                                        </#if>
                                                    </div>
                                                    <#if !sbl.hasSubMenu()>
                                                        <ol class="dd-list">
                                                            <#assign level2menus = sbl.getSubmenus()/>
                                                            <#list level2menus as level2>
                                                                <li class="dd-item dd3-item" data-id="${level2.getId()}">
                                                                    <div class="dd-handle dd3-handle"></div>
                                                                    <div class="dd3-content">
                                                                        ${level2.getText()}
                                                                        <#if FtlOperationUtil.isNull(level2.getUrl()) >
                                                                            <a style="float:right;" class="btn mini blue" onclick="editMenu(${level2.getId()}, '', '${level2.getText()}')"><i class="fa fa-edit"></i>编辑</a>
                                                                        <#else>
                                                                            <a style="float:right;" class="btn mini blue" onclick="editMenu(${level2.getId()}, '${level2.getUrl()}', '${level2.getText()}')"><i class="fa fa-edit"></i>编辑</a>
                                                                        </#if>
                                                                        <#if level2.hasSubMenu()>
                                                                            <a style="float:right;" class="btn mini black" onclick="deleteMenu(${level2.getId()}, '${level2.getText()}')"><i class="fa fa-trash"></i>删除</a>
                                                                        <#else>
                                                                            <a style="float:right;" class="btn mini black" onclick="alert('指定了Url或者有子菜单的菜单项不能被删除，请先去掉Url或者把所有子菜单项移开并提交！');"><i class="fa fa-trash"></i>删除</a>
                                                                        </#if>
                                                                        <#if FtlOperationUtil.isNull(level2.getUrl()) >
                                                                            <a style="float:right;" class="btn mini green" onclick="addSubMenu('${level2.getText()}', '${level2.getIndex()}', '${level2.getLevel()}')"><i class="fa fa-plus"></i>添加子菜单</a>
                                                                        <#else>
                                                                            <a style="float:right;" class="btn mini green" onclick="alert('指定了Url的菜单项不能添加子菜单，请先通过编辑去掉Url');"><i class="fa fa-plus"></i>添加子菜单</a>
                                                                        </#if>
                                                                    </div>
                                                                    <#if !level2.hasSubMenu()>
                                                                        <ol class="dd-list">
                                                                            <#assign level3menus = level2.getSubmenus()/>
                                                                            <#list level3menus as level3>
                                                                                <li class="dd-item dd3-item" data-id="${level3.getId()}">
                                                                                    <div class="dd-handle dd3-handle"></div>
                                                                                    <div class="dd3-content">
                                                                                        ${level3.getText()}
                                                                                        <#if FtlOperationUtil.isNull(level3.getUrl()) >
                                                                                            <a style="float:right;" class="btn mini blue" onclick="editMenu(${level3.getId()}, '', '${level3.getText()}')"><i class="fa fa-edit"></i>编辑</a>
                                                                                        <#else>
                                                                                            <a style="float:right;" class="btn mini blue" onclick="editMenu(${level3.getId()}, '${level3.getUrl()}', '${level3.getText()}')"><i class="fa fa-edit"></i>编辑</a>
                                                                                        </#if>
                                                                                        <#if level3.hasSubMenu()>
                                                                                            <a style="float:right;" class="btn mini black" onclick="deleteMenu(${level3.getId()}, '${level3.getText()}')"><i class="fa fa-trash"></i>删除</a>
                                                                                        <#else>
                                                                                            <a style="float:right;" class="btn mini black" onclick="alert('指定了Url或者有子菜单的菜单项不能被删除，请先去掉Url或者把所有子菜单项移开并提交！');"><i class="fa fa-trash"></i>删除</a>
                                                                                        </#if>
                                                                                        <#--<#if FtlOperationUtil.isNull(level3.getUrl()) >-->
                                                                                            <#--<a style="float:right;" class="btn mini green" onclick="addMenu(${level3.getId()})"><i class="fa fa-plus"></i>添加子菜单</a>-->
                                                                                        <#--<#else>-->
                                                                                            <#--<a style="float:right;" class="btn mini green" onclick="alert('指定了Url的菜单项不能添加子菜单，请先通过编辑去掉Url');"><i class="fa fa-plus"></i>添加子菜单</a>-->
                                                                                        <#--</#if>-->
                                                                                    </div>
                                                                                </li>
                                                                            </#list>
                                                                        </ol>
                                                                    </#if>
                                                                </li>
                                                            </#list>
                                                        </ol>
                                                    </#if>
                                                </li>
                                            </#list>
                                        </ol>
                                    </div>
                                </div>
                                <!-- 显示菜单树 end -->
								<div  class="controls controls-row">
							    <div id="Pagination" class="pagination"></div>
							    </div>
							   </form>
                        </div>
                     </div>
                    </div>
                    </div>
                    </div>
                </div>
            </div>
 
 
	</body>
 
</html>




